<!--
 * @Author: 熊志伟 xiongzhiwei
 * @Date: 2024-11-08 13:34:16
 * @LastEditors: wangshuixin 2412658453@qq.com
 * @LastEditTime: 2025-01-22 10:26:22
 * @FilePath: \sr_system_manager_ui\src\components\FileUpload\index.vue
 * @Description: 文件上传组件
-->
<template>
  <div>
    <x-file-upload
      v-model="props.modelValue"
      v-bind="$attrs"
      :url="props.url"
      :file-to-pdf="fileToPdf"
      :drag="props.drag"
      :limit="props.limit"
      :fileSize="props.fileSize"
      :fileType="props.fileType"
      :isShowTip="props.isShowTip"
      :width="props.width"
      :maxHeight="props.maxHeight"
      :height="props.height"
      :disabled="props.disabled"
      :showList="props.showList"
      :needParse="props.needParse"
      :specificRequirement="props.specificRequirement"
    >
      <template #tip>
        <slot name="tip"></slot>
      </template>
      <template #specificRequirement>
        <slot name="specificRequirement"></slot>
      </template>
    </x-file-upload>
  </div>
</template>

<script setup lang="ts">
import { fileToPdfReq } from '@/api/common'

const props = defineProps({
  modelValue: [String, Object, Array],
  url: {
    type: String,
    default: import.meta.env.VITE_APP_BASE_API + "/base/api/attachment/upload",
  },
  drag: {
    type: Boolean,
    default: false
  },
  // 数量限制
  limit: {
    type: Number,
    default: 20,
  },
  // 大小限制(MB)
  fileSize: {
    type: Number,
    default: 100,
  },
  // 文件类型, 例如['png', 'jpg', 'jpeg']
  fileType: {
    type: Array,
    default: () => ["doc", "docx", "xls", "xlsx", "txt", "pdf", "png", "jpg", "jpeg"]
  },
  // 是否显示提示
  isShowTip: {
    type: Boolean,
    default: true
  },
  width: { // 拖拽上传的容器宽度
    type: String,
    default: '560px'
  },
  maxHeight: { // 拖拽上传的容器宽度
    type: String,
    default: '300px'
  },
  height: { // 拖拽上传的容器高度
    type: String,
    default: '186px'
  },
  disabled: { // 是否禁用上传
    type: Boolean,
    default: false
  },
  showList: { //  是否显示上传列表文件
    type: Boolean,
    default: true
  },
  needParse: { //  是否需要前端解析文件
    type: Boolean,
    default: false
  },
  specificRequirement: { // 具体要求文字
    type: String
  }
});

const { runAsync: fileToPdf } = useRequest(fileToPdfReq, {
  manual: true
})
</script>
